<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <title>Title</title>
  <link rel="stylesheet" href="../libs/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../stylesheets/common.css">
</head>
<body>

<nav class="navbar navbar-expand-sm navbar-dark bg-primary">
  <a class="navbar-brand" href="#">
	  <img width="30" src="../images/wbb.jpeg" alt="">
  </a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link" href="../index.html">首页</a>
      </li>
      <li class="nav-item active">
        <a class="nav-link" href="./posts.html">文章</a>
      </li>
      <li class="nav-item ">
        <a class="nav-link" href="../about.html">关于我们</a>
      </li>
    </ul>
  </div>
</nav>
<section class="content">
	<aside class="bg-info">
		<a class="nav-link text-light" href="../index.html">首页</a>
		<a class="nav-link text-danger" href="./posts.html">文章</a>
		<a class="nav-link text-light" href="../about.html">关于我们</a>
	</aside>
	<main>
		<div class="d-flex justify-content-between align-items-center">
			<h1>文章详情</h1>
		</div>
		
		<div class="detail"></div>
		<a href="javascript:void(0)" class="btn btn-info edit">编辑</a>
		<button class="btn btn-danger">删除</button>
	</main>
</section>

<script src="../js/jquery-3.5.1.js"></script>
<script src="../libs/bootstrap/js/bootstrap.bundle.js"></script>
<script>

function searchParse(){
	var resultObj = {};
	var search = window.location.search;
	if(search && search.length > 1){
		var search = search.substring(1);
		var items = search.split('&');     
		for(var index = 0 ; index < items.length ; index++ ){   
			if(! items[index]){
				continue;
			}             
			var kv = items[index].split('='); 
			resultObj[kv[0]] = typeof kv[1] === "undefined" ? "":kv[1];
		}                
	} 
	return resultObj;
}

const query = searchParse()
$(".edit").attr("href", `./edit.html?id=${query.id}`)
$.ajax({
	url: `http://120.27.209.174:1010/api/v1/posts/${query.id}`,
	success(res) {
		console.log(res)
		$(".detail").html(res.detail)
	}
})

</script>
</body>
</html>
